package main

import (
	"fmt"
	"regexp"
	"strconv"
	"strings"
	"time"
)

func main() {
	fmt.Println(calcPrice(1001))
	fmt.Println(calcPrice(1001.2))
	fmt.Println(calcPrice(999))
	fmt.Println(calcPrice(999.23))
	fmt.Println(calcPrice(999.85))
	fmt.Println(calcPrice(999.26))
	fmt.Println(calcPrice(999.05))

	cookie := `_shcid=dRyIhunJ9XNS1BDblpek; 81456345Domain=.shihuo.cn; sh_u=WEBSESSIONEaQBpk; sensorsdata2015jssdkcross={"distinct_id":"1756d30f6cf1bb-0c7a27226ea3a2-30621062-334443-1756d30f6d0185","$device_id":"1756d30f6cf1bb-0c7a27226ea3a2-30621062-334443-1756d30f6d0185","props":{"$latest_traffic_source_type":"直接流量","$latest_referrer":"","$latest_referrer_host":"","$latest_search_keyword":"未取到值_直接打开"}}u=1231asd`
	r := getDetailUID(cookie)
	fmt.Println(r)

	fmt.Printf("%+v\n", strings.Split("张,21", ","))

	a()

	fmt.Println(time.Now().Unix())
}

func calcPrice(data float64) string {
	if data >= 1000 {
		res := int(data)
		return strconv.Itoa(res)
	} else {
		res := data * 10
		tmp := int(res)
		res = float64(tmp) / 10

		return strconv.FormatFloat(res, 'f', -1, 64)
	}
}

func getDetailUID(uids string) int {
	var (
		re  = regexp.MustCompile(`u=(\d+)`)
		uid int
	)
	if len(re.FindStringIndex(uids)) >= 1 {
		group := re.FindStringSubmatch(uids)[1]
		uid64, _ := strconv.ParseInt(group, 10, 64)
		uid = int(uid64)
	}
	return uid
}

func a() {
	var (
		size  string = "asd,ad"
		color string = "foo"
	)
	_size := strings.Split(size, ",")
	attrs := []string{color}
	attrs = append(attrs, _size...)

	fmt.Println(attrs)
}
